package pers.cocoadel.springcloud.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pers.cocoadel.springcloud.domain.Account;
import pers.cocoadel.springcloud.entities.CommonResult;
import pers.cocoadel.springcloud.service.AccountService;
import java.math.BigDecimal;

@RestController
public class AccountController
{
    private final AccountService accountService;

    @Autowired
    public AccountController(AccountService accountService)
    {
        this.accountService = accountService;
    }

    @PostMapping("/account/decrease")
    public CommonResult<Account> decrease(@RequestParam("userId") Long userId,
                                          @RequestParam("money") BigDecimal money)
    {
        accountService.decrease(userId, money);
        return new CommonResult<>(200, "Ok", null);
    }
}
